import { defineStore } from 'pinia'
interface UserInfoType {
  userName?: string
}
export const userStore = defineStore('user', {
  state () {
    return {
      token: '',
      userInfo: {}
    }
  },
  getters: {
    getToken (state: { token: string }): string {
      return state.token
    },
    getUserInfo (state: { userInfo: object }): UserInfoType {
      return state.userInfo
    }
  },
  actions: {
    setToken (value: string) {
      this.token = value
    },
    setUserInfo (value: object) {
      this.userInfo = value
    },
    resetUserInfo () {
      this.token = ''
      this.userInfo = {}
    }
  },
  persist: {
    enabled: true,
    strategies: [{ storage: sessionStorage, paths: ['token', 'userInfo'] }]
  }
})
